/**
 * Created by ajhin on 2/25/2015.
 */
package com.societyGames.grid
{
import flash.display.DisplayObject;
import flash.display.Sprite;

public class Grid extends Sprite
{
  private var _spaceWidth:Number;
  private var _spaceHeight:Number;

  public function Grid(spaceWidth:Number, spaceHeight:Number)
  {
    _spaceWidth = spaceWidth;
    _spaceHeight = spaceHeight;
  }

  public function addObject(gridX:Number, gridY:Number, displayObject:DisplayObject = null):GridObject
  {
    var gridObject:GridObject = new GridObject(this);
    gridObject.displayObject = displayObject;
    gridObject.gridX = gridX;
    gridObject.gridY = gridY;
  }

  internal function xFromGridX(gridX:Number):Number
  {
    return _spaceWidth * gridX;
  }

  internal function yFromGridY(gridY:Number):Number
  {
    return _spaceHeight * gridY;
  }

  internal function replaceDisplayObject(oldDisplayObject:DisplayObject, newDisplayObject:DisplayObject):void
  {
    if (oldDisplayObject != null)
    {
      this.removeChild(oldDisplayObject);
    }
    if (newDisplayObject != null)
    {
      this.addChild(newDisplayObject);
    }
  }
}
}
